package com.lankystar.sos.dao.impl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.lankystar.sos.dao.IRoomDao;
import com.lankystar.sos.model.Room;
import com.lankystar.sos.model.User;

@Repository
public class RoomDaoImpl implements IRoomDao{

	@Autowired
	private SessionFactory sf;
	public Session getSession(){
		System.err.println("session开启！！");
		return sf.getCurrentSession();
	}
	@Override
	public void addRoom(Room record) {
		getSession().save(record);
	}
	@Override
	public void deleteRoom(Room record) {
		getSession().delete(record);
	}
	@Override
	public Room selectRoomBysos_id(Integer sos_id) {
		String sql = "from Room where sos_id="+sos_id+"";
		Room record = (Room) getSession().createQuery(sql).uniqueResult();
		return record;
	}
	@Override
	public User selectUserByuserId(Integer userId) {
		User user = (User) getSession().createQuery("from User where userId=:userId")
								       .setParameter("userId", userId)
									   .uniqueResult();
		return user;
	}
}
